package com.yinhe.group.sb.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.yinhe.group.sb.domain.YhdBaseinfo;
import com.yinhe.group.sb.service.IYhdBaseinfoService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.yinhe.common.annotation.Log;
import com.yinhe.common.core.controller.BaseController;
import com.yinhe.common.core.domain.AjaxResult;
import com.yinhe.common.enums.BusinessType;

import com.yinhe.common.utils.poi.ExcelUtil;
import com.yinhe.common.core.page.TableDataInfo;
import org.springframework.web.multipart.MultipartFile;

/**
 * 新基本信息Controller
 * 
 * @author yinhe
 * @date 2023-02-10
 */
@RestController
@RequestMapping("/system/baseinfoh")
public class YhdBaseinfoController extends BaseController
{
    @Autowired
    private IYhdBaseinfoService yhdBaseinfoService;

    /**
     * 查询新基本信息列表
     */

    @GetMapping("/list")
    public TableDataInfo list(YhdBaseinfo yhdBaseinfo)
    {
        startPage();
        List<YhdBaseinfo> list = yhdBaseinfoService.selectYhdBaseinfoList(yhdBaseinfo);
        return getDataTable(list);
    }
    @PostMapping("/importTemplate")
    public void importTemplate(HttpServletResponse response)
    {
        ExcelUtil<YhdBaseinfo> util = new ExcelUtil<YhdBaseinfo>(YhdBaseinfo.class);
        util.importTemplateExcel(response, "导入数据");
    }
    @Log(title = "读者台账", businessType = BusinessType.IMPORT)
    @PreAuthorize("@ss.hasPermi('system:baseinfoh:import')")
    @PostMapping("/importData")
    public AjaxResult importData(MultipartFile file, boolean updateSupport) throws Exception
    {
        ExcelUtil<YhdBaseinfo> util = new ExcelUtil<YhdBaseinfo>(YhdBaseinfo.class);
        List<YhdBaseinfo> mapList = util.importExcel(file.getInputStream());
        String message = yhdBaseinfoService.importContract(mapList, updateSupport);
        return AjaxResult.success(message);
    }
    /**
     * 导出新基本信息列表
     */

    @Log(title = "新基本信息", businessType = BusinessType.EXPORT)
    @PreAuthorize("@ss.hasPermi('system:baseinfoh:export')")
    @PostMapping("/export")
    public void export(HttpServletResponse response, YhdBaseinfo yhdBaseinfo)
    {
        List<YhdBaseinfo> list = yhdBaseinfoService.selectYhdBaseinfoList(yhdBaseinfo);
        ExcelUtil<YhdBaseinfo> util = new ExcelUtil<YhdBaseinfo>(YhdBaseinfo.class);
        util.exportExcel(response, list, "新基本信息数据");
    }

    /**
     * 获取新基本信息详细信息
     */

    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(yhdBaseinfoService.selectYhdBaseinfoById(id));
    }

    /**
     * 新增新基本信息
     */

    @Log(title = "新基本信息", businessType = BusinessType.INSERT)
    @PreAuthorize("@ss.hasPermi('system:baseinfoh:add')")
    @PostMapping
    public AjaxResult add(@RequestBody YhdBaseinfo yhdBaseinfo)
    {
        return toAjax(yhdBaseinfoService.insertYhdBaseinfo(yhdBaseinfo));
    }

    /**
     * 修改新基本信息
     */

    @Log(title = "新基本信息", businessType = BusinessType.UPDATE)
    @PreAuthorize("@ss.hasPermi('system:baseinfoh:edit')")
    @PutMapping
    public AjaxResult edit(@RequestBody YhdBaseinfo yhdBaseinfo)
    {
        return toAjax(yhdBaseinfoService.updateYhdBaseinfo(yhdBaseinfo));
    }

    /**
     * 删除新基本信息
     */

    @Log(title = "新基本信息", businessType = BusinessType.DELETE)
    @PreAuthorize("@ss.hasPermi('system:baseinfoh:remove')")
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(yhdBaseinfoService.deleteYhdBaseinfoByIds(ids));
    }
}
